<?php
include_once('baseModel.php');

class RfidInfo extends BaseModel {
  public $_table="rfidInfo";
  
  public $id;
  public $rfidNumber;
  public $itemInfo_id;
  
  function loadByItemInfoId($id) {
    $query = "SELECT * FROM " . $this->_table . " WHERE iteminfo_id = " . $id;
    $results = DBHelper::executeQuery($query);
    if(!$results) {
      return;
    }
    // we know there will be only one result
    $this->populateModel($results[0]);
    return $this;
  }
  
  function loadByRfid($rfid) {
    $query = "SELECT * FROM `" . $this->_table . "` WHERE `rfidNumber` = " . $rfid;
    $results = DBHelper::executeQuery($query);
    if(!$results) {
      return;
    }
    // we know there will be only one result
    $this->populateModel($results[0]);
    return $this;
  }
  
  function insert() {
    $query = "INSERT INTO `" . $this->_table ."` ";
    $query .= "(`rfidNumber`, `iteminfo_id`) ";
    $query .= "VALUES (\"".addslashes($this->rfidNumber)."\", ".addslashes($this->itemInfo_id).")";
    $success = DBHelper::updateQuery($query);
    return $success;
  }
}

?>